/*
 * @Author: zwf 240970521@qq.com
 * @Date: 2023-07-15 17:24:23
 * @LastEditors: zwf 240970521@qq.com
 * @LastEditTime: 2023-07-16 10:48:04
 * @FilePath: /esp32_motor/pin/pin.c
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include "pin.h"


typedef struct
{
    PinType type;
} PinAttr;

static PinAttr sgPin[SOC_GPIO_PIN_COUNT];

/*注册管脚*/
esp_err_t PIN_register(int pinNum, PinType type)
{
    if (pinNum >= SOC_GPIO_PIN_COUNT || sgPin[pinNum].type)
    {
        return ESP_FAIL;
    }
    sgPin[pinNum].type = type;

    return ESP_OK;
}

/*释放管脚*/
esp_err_t PIN_release(int pinNum)
{
    if (pinNum >= SOC_GPIO_PIN_COUNT || !sgPin[pinNum].type)
    {
        return ESP_FAIL;
    }
    sgPin[pinNum].type = 0;

    return ESP_OK;
}

/*获取管脚状态*/
PinType PIN_getState(int pinNum)
{
    if (pinNum >= SOC_GPIO_PIN_COUNT)
    {
        return PIN_ERROR;
    }

    return sgPin[pinNum].type;
}